package com.gxa.service.impl;

import com.gxa.common.R;
import com.gxa.mapper.NewEmployeeMapper;
import com.gxa.pojo.Employee;
import com.gxa.service.NewEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

//import java.util.List;

@Service
public class NewEmployeeServiceImpl implements NewEmployeeService{
@Autowired(required = false)
private NewEmployeeMapper newEmployeeMapper;
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R addEmployee(Employee employee) {
        List<Employee> list = newEmployeeMapper.addEmployee(employee);
        R r = new R();
        r.setCode(200);
        r.setMsg("添加成功");
        r.setData(list);
        return r;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public R deleteEmployee(Employee employee) {
       List<Employee> list =  newEmployeeMapper.deleteEmployee(employee);
        R r=new R();
        r.setCode(200);
        r.setMsg("删除成功");
        r.setData(list);
        return r;
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public R updateEmployee(Employee employee) {
        List<Employee> list =  newEmployeeMapper.updateEmployee(employee);
        R r=new R();
        r.setCode(200);
        r.setMsg("修改成功");
        r.setData(list);
        return r;

    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public R selectEmployee(Employee employee) {
        List<Employee> list = newEmployeeMapper.selectEmployee(employee);
        R r=new R();
        r.setCode(200);
        r.setMsg("查询成功");
        r.setData(list);
        return r;
    }
}
